﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
using System.IO;
using ZF.BLL;

namespace ConsoleApplication1
{
    public class tree
    {
        public tree()
        {
            childs = new List<tree>();
        }
        public int id { get; set; }
        public int parentId { get; set; }
        public string name { get; set; }
        public List<tree> childs { get; set; }
    }
     class Area
    {

         public static void a()
         {
 
             using (var dc = SiteInfo.CreateDBDataContext())
             {

                 var list=dc.H_House.Where(p=>p.H_Rent==null || p.H_Sell==null).ToList();
                 list.ForEach(p =>
                     {
                         if (p.H_Rent == null)
                         {
                             p.H_Rent = new ZF.Model.H_Rent()
                             {
                                 DZ_LeastDay = 1,
                                 DZ_Price = 1,
                                 EnterTime = "saf",
                                 HZ_ISex = 1,
                                 LeastNum = 1,
                                 RentId = 1,
                                  HouseId=p.HouseId,
                             };
                             dc.H_Rent.InsertOnSubmit(p.H_Rent);
                         }
                         if (p.H_Sell == null)
                         {
                             p.H_Sell = new ZF.Model.H_Sell()

                             {
                                 HouseId = p.HouseId,
                                 UnitPrice = 1,
                             };
                             dc.H_Sell.InsertOnSubmit(p.H_Sell);

                         }
                     });
                 dc.SubmitChanges();
             }
             
         }











        static void Main1(string[] args)
        {

            using (var dc = SiteInfo.CreateDBDataContext())
            {





                return;

                var list = dc.Dic_Area.ToList();



                var areaList = list.Select(p => new AreaTree()
                {
                    Id = p.AreaId,
                    Name = p.Name,
                    ParentId = p.ParentId,
                }).ToList();
                areaList.ForEach(p =>
                {
                    if (p.ParentId != 0)
                    {
                        var parent = areaList.FirstOrDefault(a => a.Id == p.ParentId);
                        if (parent != null)
                        {
                            parent.Childs.Add(p);
                        }
                    }
                });

                areaList = areaList.Where(p => p.ParentId == 0).ToList();




                var sstr = Newtonsoft.Json.JsonConvert.SerializeObject(areaList);

                return;

                var lines = File.ReadAllLines("area/c.txt", Encoding.GetEncoding("gb2312"));
                var p1 = "广州,肇庆,东莞,中山,深圳,佛山,珠海,汕头,韶关,江门,湛江,清远,惠州,潮州,揭阳,汕尾,梅州";
                var gzid = 0;
                foreach(var p in p1.Split(','))
                {
                    var model = new  ZF.Model.Dic_Area()
                    {
                        Name = p,
                        ParentId = 0
                    };
                    dc.Dic_Area.InsertOnSubmit(model);
                    dc.SubmitChanges();
                    if (p == "广州市")
                        gzid = model.AreaId;
                }


                foreach (var line in lines)
                {
                    var tp = line.Split('=')[0];
                    var cs = line.Split('=')[1].Split(',');
                    var ap = new  ZF.Model.Dic_Area()
                    {
                        Name = tp,
                        ParentId = gzid,
                    };
                    dc.Dic_Area.InsertOnSubmit(ap);
                    dc.SubmitChanges();
                    foreach (var c in cs)
                    {
                        var ac = new  ZF.Model.Dic_Area()
                        {
                            Name = c,
                            ParentId = ap.AreaId,
                        };
                        dc.Dic_Area.InsertOnSubmit(ac);
                    }
                    dc.SubmitChanges();
                }

            }
        }
    }
    public class AreaTree
    {
        public AreaTree()
        {
            Childs = new List<AreaTree>();
        }
        public string Name { get; set; }
        public int Id { get; set; }
        public List<AreaTree> Childs { get; set; }
        public int ParentId { get; set; }
    }
}
